-
Notifications
You must be signed in to change notification settings - Fork 1k
Avoid memcpy()-ing 0-length vectors
#6820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The C standard (before C23) says that giving invalid pointers, even with length=0, to memcpy() is undefined behaviour. R returns an invalid pointer for vectors of length 0, so avoid calls to memcpy() altogether in such cases.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6820 +/- ##
=======================================
Coverage 98.64% 98.64%
=======================================
Files 79 79
Lines 14642 14650 +8
=======================================
+ Hits 14444 14452 +8
Misses 198 198 ☔ View full report in Codecov by Sentry. |
|
Generated via commit 4773ceb Download link for the artifact containing the test results: ↓ atime-results.zip
|
MichaelChirico
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, feel free to merge whether or not you want to make my suggested change.
Do we have any way of preventing this from recurring in the future?
Co-authored-by: Michael Chirico <[email protected]>
Co-authored-by: Michael Chirico <[email protected]>
|
Maybe not literally preventing, but a sanitizer-enabled CI check should be able to catch similar problems as soon as they land on Then why does |
* Avoid memcpy()-ing 0-length vectors The C standard (before C23) says that giving invalid pointers, even with length=0, to memcpy() is undefined behaviour. R returns an invalid pointer for vectors of length 0, so avoid calls to memcpy() altogether in such cases. * Use early returns for 0-length cases Co-authored-by: Michael Chirico <[email protected]>
* Avoid memcpy()-ing 0-length vectors The C standard (before C23) says that giving invalid pointers, even with length=0, to memcpy() is undefined behaviour. R returns an invalid pointer for vectors of length 0, so avoid calls to memcpy() altogether in such cases. * Use early returns for 0-length cases Co-authored-by: Michael Chirico <[email protected]>
* Avoid `memcpy()`-ing 0-length vectors (#6820) * Avoid memcpy()-ing 0-length vectors The C standard (before C23) says that giving invalid pointers, even with length=0, to memcpy() is undefined behaviour. R returns an invalid pointer for vectors of length 0, so avoid calls to memcpy() altogether in such cases. * Use early returns for 0-length cases Co-authored-by: Michael Chirico <[email protected]> * Avoid memcpy() of empty vector (#6911) * Avoid memcpy() of empty vector * in getidcols() too * Add a test case Distilled from the `melt()` call here: https://github.com/gdemin/expss/blob/d498caf72a9938ac71b9e06fd61485cd0347d607/tests/testthat/test_subtotal.R#L161-L166 * NEWS entry --------- Co-authored-by: Michael Chirico <[email protected]> Co-authored-by: Michael Chirico <[email protected]>

The C standard (before C23) says that giving invalid pointers, even with length=0, to
memcpy()is undefined behaviour. R returns an invalid pointer for vectors of length 0, so avoid calls tomemcpy()altogether in such cases.Fixes: #6819